require "rwebunit"

$:.unshift File.dirname(__FILE__)
require "kongming_pages.rb"

class TestWuning < RWebUnit::WebTestCase

   def initialize(name) 
      super(name)
   end

   def setup
      super
      openBrowser("http://localhost:3721", "/home")
   end

   def teardown
      super
      closeBrowser()
   end

   def test_homepage_exists()
       kongming_homepage = KongmingHomePage.new(@web_tester, "Welcome")
   end

   def test_all_links_exist
       kongming_homepage = KongmingHomePage.new(@web_tester, "Welcome")
       kongming_homepage.assertTheListLinkPresent()
       kongming_homepage.assertDashboardLinkPresent
       kongming_homepage.assertTestCenterLinkPresent
       kongming_homepage.assertTestWebServiceLinkPresent
   end

   # enter text in a text field, then click a button
   def test_format_xml
       kongming_homepage = KongmingHomePage.new(@web_tester, "Welcome")
       kongming_xmlformatter_page = kongming_homepage.clickXMLFormatterLink
       kongming_xmlformatter_page.enterXml("<name><first>James</first><last>Bond</last></name>")
       kongming_xmlformatter_page.clickFormat
   end

   # Invoke link to populate date using javascripts (clickFillExampleLink)
   # Calling submit
   # Check special text before and after submit
   def test_format_xml_sample
       kongming_homepage = KongmingHomePage.new(@web_tester, "Welcome")
       kongming_xmlformatter_page = kongming_homepage.clickXMLFormatterLink
       kongming_xmlformatter_page.clickFillExampleLink
       @web_tester.assertElementNotPresent("formatted_xml")
       kongming_xmlformatter_page.submit
       @web_tester.assertElementPresent("formatted_xml")
   end

   # web testcase can utilize useful methods defined in test_utils
   def test_can_call_utils
       kongming_homepage = KongmingHomePage.new(@web_tester, "Welcome")
       kongming_xmlformatter_page = kongming_homepage.clickXMLFormatterLink
       kongming_xmlformatter_page.enterXml("<date><now>" + getToday + "</now></date>")
       kongming_xmlformatter_page.clickFormat
   end

   def test_combobox
       kongming_homepage = KongmingHomePage.new(@web_tester, "Welcome")
       kongming_httpcaller_page = kongming_homepage.clickHttpCallerLink
       # html:
       #     <select name="method">
       #         <option value="POST">HTTP POST </option>
       #         <option value="GET"> HTTP GET </option>
       #     </select>

       @web_tester.assertOptionPresent("method", "HTTP POST")  # trimmed 
       @web_tester.assertOptionPresent("method", "HTTP GET")
       @web_tester.assertOptionNotPresent("method", "PUT")
       @web_tester.assertOptionValuePresent("method", "POST")
       @web_tester.assertOptionValuePresent("method", "GET")
       @web_tester.assertOptionValueNotPresent("method", "HEAD")
   end

end